package com.zt.yongxinbao.controller;

import com.zt.yongxinbao.dto.CommentParam;
import com.zt.yongxinbao.entity.EvaluationGoods;
import com.zt.yongxinbao.service.EvaluationGoodsService;
import com.zt.yongxinbao.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "goods/comment")
public class EvaluationGoodsController {
    @Autowired
    private EvaluationGoodsService evaluationGoodsService;
    @GetMapping(value = "/getComment/{goodsName}")
    public CommonResult getComment(@PathVariable String goodsName){
        List<EvaluationGoods> evaluationGoods=evaluationGoodsService.getComment(goodsName);
        return CommonResult.success(evaluationGoods);
    }
    @PostMapping(value = "/getCommentByGoodsAndCustomerName")
    public CommonResult getCommentByGoodsAndCustomerName(@RequestBody CommentParam commentParam){
        List<EvaluationGoods> evaluationGoods=evaluationGoodsService.getCommentByGoodsAndCustomerName(commentParam.getGoodsTitle(),commentParam.getCustomerName());
        return CommonResult.success(evaluationGoods);
    }
    @PostMapping(value = "/insertComment")
    public CommonResult insertComment(@RequestBody EvaluationGoods evaluationGoods){
        if (evaluationGoodsService.insertComment(evaluationGoods)) return CommonResult.success("评论成功");
        return CommonResult.failed("评论失败，请重试");
    }
}
